
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.MailParseException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;



public class MailSenderManagement {
    private JavaMailSender mailSender;
 
    public void setMailSender(CustomMailSender mailSender) {
        this.mailSender = mailSender;
    }
    
    public void sendMail(String dear, String content,SimpleMailMessage simpleMailMessage) {
        
        MimeMessage message = mailSender.createMimeMessage();
  
        try{
         MimeMessageHelper helper = new MimeMessageHelper(message, true);
         
         helper.setFrom(simpleMailMessage.getFrom());
         helper.setTo(simpleMailMessage.getTo());
         helper.setSubject(simpleMailMessage.getSubject());
         helper.setText(simpleMailMessage.getText(),true);
  
//         FileSystemResource file = new FileSystemResource("C:\\log.txt");
//         helper.addAttachment(file.getFilename(), file);
  
        }catch (MessagingException e) {
            throw new MailParseException(e);
        }
        mailSender.send(message);
   }
}
